<?php 
class notificacao_linkModel extends Model{
    public $tabela            = 'notificacao_link';
    public $pkey              = 'cod';
    public $model_label       = 'Links';
    public $model_description = 'Os links agrupam as notificações';
    public $dados  = array(        
         'cod' => array(
	    'name'     => 'Código',
	    'type'     => 'int',
	    'size'     => '11',
	    'pkey'    => true,
	    'ai'      => true,
	    'grid'    => true,
	    'display' => true,
	    'private' => true
        ),

        'url' => array(
	    'name'     => 'Url',
	    'type'     => 'varchar',
	    'size'     => '128',
	    'grid'    => true,
	    'display' => true,
        ),
        'button'     => array('button' => 'Gravar Link')
     );
    
    private function addLink($url){
        $var['url'] = $url;
        return parent::inserir($var);
    }
    
    public function getCodLink($url){
        $item = $this->getItem($url, 'url');
        if(!empty($item)) return $item['cod'];
        
        if(!$this->addLink($url)) return false;
        return $this->getLastId();
        
    }
}
?>